<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
        <el-form-item label="用户组名称" prop="groupName">
          <el-input v-model="queryParams.groupName" placeholder="请输入用户组名称" clearable size="small" style="width: 240px"
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="角色名称" prop="roleName">
          <el-input v-model="queryParams.roleName" placeholder="请输入角色名称" clearable size="small" style="width: 240px"
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
       
        <el-form-item>
          <el-button v-preventReClick type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button v-preventReClick icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-table v-loading="loading" :data="roleList" class="margin-top">
        <el-table-column label="用户组名称" prop="groupName" :show-overflow-tooltip="true"/>
        <el-table-column label="角色名称" prop="roleName" :show-overflow-tooltip="true"/>
        <el-table-column label="角色编码" prop="roleCode" />
        <el-table-column label="创建时间" prop="createTime" :formatter="$util.YYMM" />
        <el-table-column label="创建人" prop="creatorName" />
        <el-table-column label="操作" align="center" fixed="right" width="200" class-name="small-padding fixed-width">
            <template v-slot="scope">
              <div >
                       <el-button v-preventReClick size="mini" type="text" @click="handleView(1, scope.row)">查看用户</el-button>
                       <span class="spans">|</span>
                      <el-button v-preventReClick size="mini" type="text" @click="handleView(2, scope.row)"
                      v-hasPermi="['system:role:delete']">对象查看功能授权</el-button>
              </div>
            </template>
        </el-table-column>
      </el-table>
  
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                  @pagination="getList"/>
  
  
      <!-- 查看组件 -->
      <ViewUserDialog ref="ViewUserDialog" ></ViewUserDialog>
      <ViewRoleDialog ref="ViewRoleDialog" ></ViewRoleDialog>
    </div>
  </template>
  
  <script>
  import {
    groupRoles, groupRoleUsers, groupRoleFunction
  } from "@/api/bpm/userGroup";
  
  import ViewUserDialog from "./components/viewUser.vue"
  import ViewRoleDialog from "./components/viewRole.vue"
  
  
  export default {
    components:{
      ViewUserDialog, ViewRoleDialog
    },
    name: "UserGroupRole",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [],
        // 弹出层标题

        // 查询参数
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          roleName: undefined,
          groupName: undefined
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询角色列表 */
      getList() {
        this.loading = true;
        groupRoles(this.queryParams).then(
          response => {
            this.roleList = response.data.list;
            this.total = response.data.total;
            this.loading = false;
          }
        ).catch(err => this.loading = false)
      },
      /**查看详情 */
      handleView(index, row){
        const { id } = row
        if(index== 1){
          this.$refs.ViewUserDialog.init(id)
        }else{
          this.$refs.ViewRoleDialog.init(id)
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
  </script>
  